﻿using System;
using System.Collections.Generic;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace YJKInspectModel.ModelValidation.ClearHeightCheck
{
	public class RequestHandler : IExternalEventHandler
	{
		public Request Request
		{
			get
			{
				return this.m_request;
			}
		}

		public string GetName()
		{
			return "Check ClearHeight Event";
		}

		public void Execute(UIApplication uiapp)
		{
			UIDocument activeUIDocument = uiapp.ActiveUIDocument;
			Document document = activeUIDocument.ActiveView.Document;
			switch (this.Request.Take())
			{
			case RequestId.reCalculation:
				if (ApplicationClearHeight.thisApp.m_fun.StartCheckClearHeight())
				{
					ApplicationClearHeight.thisApp.m_ShowClearHeightForm.m_LevelItemInfo = ApplicationClearHeight.thisApp.m_fun.getClearHeightInLevel();
					ApplicationClearHeight.thisApp.m_ShowClearHeightForm.initTreeView();
					return;
				}
				break;
			case RequestId.ZoomElement:
				ApplicationClearHeight.thisApp.m_fun.ZoomElement();
				return;
			case RequestId.PickElements:
			{
				List<ElementId> listElement = new List<ElementId>();
				listElement = ApplicationClearHeight.thisApp.m_fun.SelectElement();
				List<Element> list = new List<Element>();
				ApplicationClearHeight.thisApp.m_ShowClearHeightForm.RefreshTreeView(listElement, list);
				RevitVersionFuncs.SetSelection(activeUIDocument.Selection, list);
				activeUIDocument.RefreshActiveView();
				return;
			}
			case RequestId.RefreshFillRegion:
				new ClearHeightCheckFun(uiapp).RefreshClearHeightPlan();
				return;
			case RequestId.Remove:
				ApplicationClearHeight.thisApp.m_fun = null;
				ApplicationClearHeight.thisApp.m_ShowClearHeightForm = null;
				break;
			default:
				return;
			}
		}

		private Request m_request = new Request();
	}
}
